import { Card, Space, Button, Select } from "antd";
import { useAppDispatch, useAppSelector } from "@/store/hooks";
import {
  changeModal,
  changeParams,
  getCountryAsync,
} from "@/store/settingCountry/settingCountrySlice";
import { shallowEqual } from "react-redux";

export default function Filter() {
  const dispatch = useAppDispatch();

  const { params, table } = useAppSelector(
    (state) => state.settingCountry,
    shallowEqual
  );
  const {
    config: { data: { data: { user_channel_list = [] } = {} } = {} } = {},
  } = useAppSelector((state) => state.app, shallowEqual);
  return (
    <Card>
      <Space
        wrap
        size="large"
        className="w-full flex justify-between"
        classNames={{ item: "last:ml-auto" }}
      >
        <label>
          <span>渠道：</span>
          <Select
            className="min-w-[120px]"
            value={params.channel}
            options={[{ label: "全部", value: "" }, ...user_channel_list]}
            onChange={(channel) => {
              dispatch(changeParams({ channel }));
            }}
          />
        </label>
        <Button.Group>
          <Button
            type="primary"
            ghost
            onClick={(): void => {
              dispatch(changeModal({type: 'create', open: true}))
            }}
          >
            创建
          </Button>
          <Button
            loading={table.status === "loading"}
            type="primary"
            onClick={(): void => {
              dispatch(getCountryAsync({ ...params }));
            }}
          >
            查询
          </Button>
        </Button.Group>
      </Space>
    </Card>
  );
}
